package cn.com.ccxcredit.wallet.ui;

import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatEditText;
import android.util.Log;

import java.math.BigInteger;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.com.ccxcredit.wallet.BaseActivity;
import cn.com.ccxcredit.wallet.R;
import cn.com.ccxcredit.wallet.observer.SimpleObserve;
import cn.com.ccxcredit.wallet.util.HttpUiTips;
import credit.ccx.com.walletcore.base.BaseApplication;
import credit.ccx.com.walletcore.helper.TransferHelper;
import credit.ccx.com.walletcore.util.SPUtils;
import huixue.cn.com.library.base.SimpleActivity;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class TransferKSActivity extends SimpleActivity {

    @BindView(R.id.et_trans_coin)
    AppCompatEditText etTransCoin;
    @BindView(R.id.et_receive_address)
    AppCompatEditText etReceiveAddress;
    @BindView(R.id.btn_confirm)
    AppCompatButton btnConfirm;

    @Override
    public int getLayout() {
        return R.layout.activity_transfer_ks;
    }

    @Override
    public void initView() {

    }

    @Override
    public void addEvent() {

    }

    @OnClick(R.id.btn_confirm)
    public void onViewClicked() {
        HttpUiTips.showDialog(this,true, "loading...");
        Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                String path = (String) SPUtils.get(BaseApplication.application,"P_ETH","");
                String msg = TransferHelper.localSendEther("",path,etReceiveAddress.getText().toString().trim(),
                        new BigInteger(etTransCoin.getText().toString().trim()));
                e.onNext(msg);
            }
        }).subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(new SimpleObserve<String>() {
              @Override
              public void onNext(String s) {
                  super.onNext(s);
                  HttpUiTips.dismissDialog(TransferKSActivity.this);
              }
          });
    }

}
